from django.db import models

# Create your models here.
class LicenseApply(models.Model):
    
    def_info = "当前版本授权给......，用于授权......项目，芯片架构为......，"
    proj_desc = models.TextField(verbose_name='版本描述', default=def_info)

    user_name = models.CharField(max_length=64, verbose_name='用户名称')
    user_id = models.CharField(max_length=32, verbose_name='用户ID')
    ver_id = models.CharField(max_length=32, verbose_name='版本ID')
    
    tot_num = models.CharField(max_length=32, verbose_name='License总数')
    left_num = models.CharField(max_length=32, verbose_name='License剩余')
    
    start_date = models.DateField("有效期始")
    end_date = models.DateField("有效期止")
    
    def __str__(self):
        return self.user_name
    
    class Meta:
        verbose_name_plural = '授权信息'

class LicenseDisplay(models.Model):
    lic_key = models.ForeignKey(LicenseApply, on_delete=models.CASCADE)
    lic_time = models.DateTimeField("申请时间")
    ip_addr = models.CharField(max_length=32,verbose_name="IP地址")
    macaddr = models.CharField(max_length=32,verbose_name="MAC地址")
    hard_no = models.CharField(max_length=32,verbose_name="硬件序列号")

    def __str__(self):
        return str(self.lic_time)
    
    class Meta:
        verbose_name_plural = '申请历史'

# shell
# from cert.models import LicenseApply, LicenseDisplay
# from datetime import datetime
# datetime.now().date()
